package cn.iocoder.yudao.module.handguard.controller.admin.homeone;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.handguard.controller.admin.homeone.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.homeone.HomeOneDO;
import cn.iocoder.yudao.module.handguard.convert.homeone.HomeOneConvert;
import cn.iocoder.yudao.module.handguard.service.homeone.HomeOneService;

@Tag(name = "管理后台 - 首页成交榜-即使滚动数据")
@RestController
@RequestMapping("/hutai/home-one")
@Validated
public class HomeOneController {

    @Resource
    private HomeOneService homeOneService;

//    @PostMapping("/create")
//    @Operation(summary = "创建首页成交榜-即使滚动数据")
//    @PreAuthorize("@ss.hasPermission('hutai:home-one:create')")
//    public CommonResult<Long> createHomeOne(@Valid @RequestBody HomeOneCreateReqVO createReqVO) {
//        return success(homeOneService.createHomeOne(createReqVO));
//    }

//    @PutMapping("/update")
//    @Operation(summary = "更新首页成交榜-即使滚动数据")
//    @PreAuthorize("@ss.hasPermission('hutai:home-one:update')")
//    public CommonResult<Boolean> updateHomeOne(@Valid @RequestBody HomeOneUpdateReqVO updateReqVO) {
//        homeOneService.updateHomeOne(updateReqVO);
//        return success(true);
//    }

//    @DeleteMapping("/delete")
//    @Operation(summary = "删除首页成交榜-即使滚动数据")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('hutai:home-one:delete')")
//    public CommonResult<Boolean> deleteHomeOne(@RequestParam("id") Long id) {
//        homeOneService.deleteHomeOne(id);
//        return success(true);
//    }

    @GetMapping("/get")
    @Operation(summary = "获得首页成交榜-即使滚动数据")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('hutai:home-one:query')")
    public CommonResult<HomeOneRespVO> getHomeOne(@RequestParam("id") Long id) {
        HomeOneDO homeOne = homeOneService.getHomeOne(id);
        return success(HomeOneConvert.INSTANCE.convert(homeOne));
    }

    @GetMapping("/list")
    @Operation(summary = "获得首页成交榜-即使滚动数据列表")
    @PreAuthorize("@ss.hasPermission('hutai:home-one:query')")
    public CommonResult<List<HomeOneRespVO>> getHomeOneList() {
        List<HomeOneDO> list = homeOneService.getHomeOneList();
        return success(HomeOneConvert.INSTANCE.convertList(list));
    }

    @PostMapping("/create")
    @Operation(summary = "创建首页成交榜-即使滚动数据")
    @PreAuthorize("@ss.hasPermission('hutai:home-one:create')")
    public CommonResult<Long> updateAddData(@Valid @RequestBody HomeReqVO reqVO) {
        return success(homeOneService.updateAddData(reqVO));
    }

//    @GetMapping("/listStr")
//    @Operation(summary = "获得首页成交榜-即使滚动数据列表")
//    @PreAuthorize("@ss.hasPermission('hutai:home-one:query')")
//    public CommonResult<String[]> getHomeOneListStr() {
//        List<HomeOneDO> list = homeOneService.getHomeOneList();
//        String [] stringList = new String[list.size()];
//        for (int i=0;i<list.size();i++){
//            stringList[i] = list.get(i).getTitle();
//        }
//        return success(stringList);
//    }

//    @GetMapping("/page")
//    @Operation(summary = "获得首页成交榜-即使滚动数据分页")
//    @PreAuthorize("@ss.hasPermission('hutai:home-one:query')")
//    public CommonResult<PageResult<HomeOneRespVO>> getHomeOnePage(@Valid HomeOnePageReqVO pageVO) {
//        PageResult<HomeOneDO> pageResult = homeOneService.getHomeOnePage(pageVO);
//        return success(HomeOneConvert.INSTANCE.convertPage(pageResult));
//    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出首页成交榜-即使滚动数据 Excel")
//    @PreAuthorize("@ss.hasPermission('hutai:home-one:export')")
//    @OperateLog(type = EXPORT)
//    public void exportHomeOneExcel(@Valid HomeOneExportReqVO exportReqVO,
//              HttpServletResponse response) throws IOException {
//        List<HomeOneDO> list = homeOneService.getHomeOneList(exportReqVO);
//        // 导出 Excel
//        List<HomeOneExcelVO> datas = HomeOneConvert.INSTANCE.convertList02(list);
//        ExcelUtils.write(response, "首页成交榜-即使滚动数据.xls", "数据", HomeOneExcelVO.class, datas);
//    }

}
